package largestAltitude;

import java.util.Arrays;
import java.util.Map;

public class Solution {
    public int largestAltitude(int[] gain) {
        // h[i] - h[i+1] = gain[i];
        // h[i+1] = gain[i] + h[i];
        // h[0] = 0;
//        int[] h = new int[gain.length+1];
//        int max = 0;
//        for (int i = 0; i < gain.length; i++) {
//            h[i+1] = h[i] + gain[i];
//            max = Math.max(h[i+1],max);
//        }
//        return max;

        int max = 0;
        int sum = 0;
        for (int v: gain) {
            sum+=v;
            max = Math.max(max,sum);
        }
        return max;
    }
}
